<?
class Model_Session {
	
	function sessionExtInit($session_info) {
		if (isset ( $session_info ['uid'] ) && $session_info) {
			$_session_extinfo ['user_info'] = $this->initUInfo ( $session_info );
		}
		$_session_extinfo ['site_info'] = $this->initSInfo ( $session_info );
		return $_session_extinfo;
	}
	
	/**
	 * session 用户信息初始化
	 */
	private function initUinfo($session_info) {
		$Members_db = new DB_Members ();
		$Members_info = $Members_db->loadInfo ( '*', array ('uid= ? ' => $session_info ['uid'] ) );
		
		return $Members_info;
	}
	
	/**
	 * session 网站信息初始化
	 */
	private function initSinfo($session_info) {
		$_s_site_info = array ();
		$_tpl_channel = 'index';
		$_server_rqurl_arr = explode ( '/', $_SERVER ['REDIRECT_URL'] );
		if ($_server_rqurl_arr [1]) {
			$_tpl_channel = $_server_rqurl_arr [1];
		}
		
		$_s_site_info ['channel'] = $_tpl_channel;
		
		return $_s_site_info;
	}
	
	/**
	 * 更新验证码
	 */
	function updateSecCode($seccode, $sid = null) {
		$cache = Zend_Registry::get ( 'MemCache' );
		$expires_offset = 300;
		if (! $sid) {
			$session_info = Zend_Registry::get ( 'CmsSessionInfo' );
			$sid = $session_info ['sid'];
		}
		$cache->save ( $seccode, $sid . "_seccode", null, $expires_offset );
	}
	
	/**
	 * 验证更新验证码
	 */
	function checkSecCode($seccode, $sid = null) {
		$cache = Zend_Registry::get ( 'MemCache' );
		if (! $sid) {
			$session_info = Zend_Registry::get ( 'CmsSessionInfo' );
			$sid = $session_info ['sid'];
		}
		$session_seccode = $cache->load ( $sid . "_seccode" );
		if ($session_seccode == $seccode) {
			return true;
		}
		return false;
	}

}